package org.example.aienglishapp.controller.operationlog;

import org.example.aienglishapp.entity.operationlog.OperationLog;
import org.example.aienglishapp.service.operationlog.OperationLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/operationlogs")
public class OperationLogController {

    private static final Logger logger = LoggerFactory.getLogger(OperationLogController.class);

    @Autowired
    private OperationLogService operationLogService;

    @PostMapping
    public void createOperationLog(@RequestBody OperationLog log) {
        logger.info("Creating operation log: {}", log);
        operationLogService.insertOperationLog(log);
    }

    @GetMapping
    public List<OperationLog> getAllOperationLogs() {
        List<OperationLog> logs = operationLogService.getAllOperationLogs();
        logger.info("Returning {} operation logs", logs.size());
        return logs;
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Void> deleteById(@PathVariable Long id) {
        logger.info("Deleting operation log with ID: {}", id);
        operationLogService.deleteById(id);
        return ResponseEntity.noContent().build();
    }
}
